4. Linux File,Directory Permissions
Since Linux is a multiuser OS it provides file authorization as a security feature to prevent people from accessing each other’s confidential files.
Linux divides authorization into 2 levels:
-
Ownership
-
Permission
Command to view file permissions:
ls -l


There are 3 permissions of each file one each for user,group and other.
- First character shows type of content:
'-' = file
d = directory

- next nine characters (rw-rw-rwx) shows the security for each owner.

- next column shows the owner of the file. In fig 1 user: “aditya314”
- next column shows the group owner of the file. In fig 1 group: “aditya314”
- next column shows the size of the file in bytes.
- next column shows the date and time the file was last modified.
- final column gives the filename.
Permissions

“rwx” characters shows operations each owner can perform on file
- r =“read” the file’s contents
- w=“write”, or modify, the file’s contents
- x=“execute” the file, only if the file is a program (software or script)
- If any of the “rwx” characters is replaced by ‘-‘, then that permission has been
revoked.
Ownership
- user – The user permissions apply only to the owner of the file or directory
- group (a collection of users)– The group permissions apply only to the group that has been assigned to the file or directory
- others – The others permissions apply to all other users on the system
Note: Whenever a user is created, by default, they are added to a new group with the same name as the username. This is called the primary group of the user.
Ex: user – john, group - john
Reading the security permissions

Ex: rw-r-xr--
- rw- = first set of 3 characters = owner of the file can “read” it (look at its contents) and “write” it (modify its contents).
- r-x = second set = means that the members of the group can only read and execute the files.
- r-- = final set = permissions allowed to anyone who has a UserID on this Linux system = anyone in Linux world can only read it.
Changing file/directory permissions with 'chmod' command
Using the command, we can set permissions (read, write, execute) on a file/directory for the owner(user), group and the world(others).
Syntax:
chmod [permissions] [filename]
List permissions of a file/directory
ls -l [file,directory name]
- 2 ways to use the command:
- Absolute (Numeric) mode
In this mode, file permissions are not represented as characters but a three-digit octal number.
In this mode, you change permissions for all 3 owners.

For Ex: '764' absolute code says the following: rwxrw-r--


- Symbolic mode
In this mode, you can modify permissions of a specific owner using mathematical symbols.


